<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="水井" prop="sj">
        <el-input v-model="queryParams.sj" placeholder="请输入水井" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="取样年份" prop="qynf">
        <el-input v-model="queryParams.qynf" placeholder="请输入取样年份" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['Laboratory_well:well:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['Laboratory_well:well:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['Laboratory_well:well:remove']">删除</el-button>
      </el-col>
      <!--   <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Laboratory_well:well:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wellList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="200px" />
      <el-table-column label="水井" align="center" prop="sj" :formatter="laboratory_well_sj_Format" />
      <!-- <el-table-column label="月份" align="center" prop="month" />
      <el-table-column label="氟(mg/L)" align="center" prop="fu" />
      <el-table-column label="氯化物(mg/L)" align="center" prop="lhw" />
      <el-table-column label="溴(mg/L)" align="center" prop="xiu" />
      <el-table-column label="硝酸盐(mg/L)" align="center" prop="xsy" />
      <el-table-column label="硫酸盐(mg/L)" align="center" prop="lxy" />
      <el-table-column label="钠(mg/L)" align="center" prop="na" />
      <el-table-column label="钾(mg/L)" align="center" prop="jia" />
      <el-table-column label="钙(mg/L)" align="center" prop="gai" />
      <el-table-column label="镁(mg/L)" align="center" prop="mei" />
      <el-table-column label="锶(mg/L)" align="center" prop="si" />
      <el-table-column label="偏硅酸(mg/L)" align="center" prop="pgs" />
      <el-table-column label="氨氮(mg/L)" align="center" prop="ad" />
      <el-table-column label="锰(mg/L)" align="center" prop="meng" />
      <el-table-column label="铁(mg/L)" align="center" prop="tie" />
      <el-table-column label="亚硝酸盐(mg/L)" align="center" prop="yxsy" />
      <el-table-column label="碳酸盐(mg/L)" align="center" prop="tsy" />
      <el-table-column label="碳酸氢盐(mg/L)" align="center" prop="tsqy" />
      <el-table-column label="电导率(us/cm)" align="center" prop="ddl" />
      <el-table-column label="TDS(mg/L)" align="center" prop="tds" />
      <el-table-column label="PH值" align="center" prop="ph" />
      <el-table-column label="锌(mg/L)" align="center" prop="xin" />
      <el-table-column label="总砷(mg/L)" align="center" prop="zk" />
      <el-table-column label="铅(μg/L)" align="center" prop="qian" />
      <el-table-column label="铬(μg/L)" align="center" prop="ge" />
      <el-table-column label="镉(μg/L)" align="center" prop="ge2" />
      <el-table-column label="镍(μg/L)" align="center" prop="nie" />
      <el-table-column label="铜(mg/L)" align="center" prop="tong" /> -->
      <el-table-column label="取样年份" align="center" prop="qynf" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.qynf, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="报表编号" align="center" prop="bbbh" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="250px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="excelhandleView(scope.row)"
          >导出</el-button            >
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['Laboratory_well:well:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['Laboratory_well:well:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改水井水质分析简对话框 -->

    <el-dialog fullscreen v-myFullscreen :title="title" :visible.sync="open" width="700px" append-to-body custom-class="myDialog">
      <TableHeader @nameChange="nameChange" :data="{
          mainTitle: '水井水质分析记录',
          company: '青岛崂山矿泉水有限公司',
          code: form.code,
        }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="水井" prop="sj">
              <el-select v-model="form.sj" placeholder="请选择水井" style="width: 100%" :disabled="openDisabled">
                <el-option v-for="dict in laboratory_well_sj" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictLabel"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="取样年份" prop="qynf">
              <!-- <el-input v-model="form.qynf" placeholder="请输入取样年份" :disabled="openDisabled" /> -->
              <el-date-picker v-model="form.qynf" type="year" placeholder="选择年份" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
                <el-form-item label="报表编号" prop="bbbh">
                  <el-input v-model="form.bbbh" placeholder="请输入报表编号" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" placeholder="请输入备注" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
        </el-row>
        <br />
        <el-divider content-position="center">水井水质分析子信息</el-divider>
        <br />
        <!-- <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddQualityLabWellSub"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteQualityLabWellSub"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
        </el-row> -->
        <el-table :data="qualityLabWellSubList" :row-class-name="rowQualityLabWellSubIndex" @selection-change="handleQualityLabWellSubSelectionChange" ref="qualityLabWellSub">
          <!-- <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          /> -->
          <el-table-column minWidth="180px" label="月份" prop="month">
            <template slot-scope="scope">
              <el-input v-model="scope.row.month" placeholder="请输入月份" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="氟(mg/L)" prop="fu">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fu" placeholder="请输入氟(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="氯化物(mg/L)" prop="lhw">
            <template slot-scope="scope">
              <el-input v-model="scope.row.lhw" placeholder="请输入氯化物(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="溴(mg/L)" prop="xiu">
            <template slot-scope="scope">
              <el-input v-model="scope.row.xiu" placeholder="请输入溴(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="硝酸盐(mg/L)" prop="xsy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.xsy" placeholder="请输入硝酸盐(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="硫酸盐(mg/L)" prop="lxy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.lxy" placeholder="请输入硫酸盐(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="钠(mg/L)" prop="na">
            <template slot-scope="scope">
              <el-input v-model="scope.row.na" placeholder="请输入钠(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="钾(mg/L)" prop="jia">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jia" placeholder="请输入钾(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="钙(mg/L)" prop="gai">
            <template slot-scope="scope">
              <el-input v-model="scope.row.gai" placeholder="请输入钙(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="镁(mg/L)" prop="mei">
            <template slot-scope="scope">
              <el-input v-model="scope.row.mei" placeholder="请输入镁(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="锶(mg/L)" prop="si">
            <template slot-scope="scope">
              <el-input v-model="scope.row.si" placeholder="请输入锶(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="偏硅酸(mg/L)" prop="pgs">
            <template slot-scope="scope">
              <el-input v-model="scope.row.pgs" placeholder="请输入偏硅酸(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="氨氮(mg/L)" prop="ad">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ad" placeholder="请输入氨氮(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="锰(mg/L)" prop="meng">
            <template slot-scope="scope">
              <el-input v-model="scope.row.meng" placeholder="请输入锰(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="铁(mg/L)" prop="tie">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tie" placeholder="请输入铁(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="亚硝酸盐(mg/L)" prop="yxsy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.yxsy" placeholder="请输入亚硝酸盐(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="碳酸盐(mg/L)" prop="tsy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tsy" placeholder="请输入碳酸盐(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="碳酸氢盐(mg/L)" prop="tsqy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tsqy" placeholder="请输入碳酸氢盐(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="电导率(us/cm)" prop="ddl">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ddl" placeholder="请输入电导率(us/cm)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="TDS(mg/L)" prop="tds">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tds" placeholder="请输入TDS(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="PH值" prop="ph">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ph" placeholder="请输入PH值" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="锌(mg/L)" prop="xin">
            <template slot-scope="scope">
              <el-input v-model="scope.row.xin" placeholder="请输入锌(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="总砷(mg/L)" prop="zk">
            <template slot-scope="scope">
              <el-input v-model="scope.row.zk" placeholder="请输入总砷(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="铅(μg/L)" prop="qian">
            <template slot-scope="scope">
              <el-input v-model="scope.row.qian" placeholder="请输入铅(μg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="铬(μg/L)" prop="ge">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ge" placeholder="请输入铬(μg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="镉(μg/L)" prop="ge2">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ge2" placeholder="请输入镉(μg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="镍(μg/L)" prop="nie">
            <template slot-scope="scope">
              <el-input v-model="scope.row.nie" placeholder="请输入镍(μg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="铜(mg/L)" prop="tong">
            <template slot-scope="scope">
              <el-input v-model="scope.row.tong" placeholder="请输入铜(mg/L)" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="取样日期" prop="qyrq" width="150">
            <template slot-scope="scope">
              <el-date-picker :editable="false" clearable v-model="scope.row.qyrq" type="date" value-format="yyyy-MM-dd" placeholder="选择取样日期" :disabled="openDisabled">
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column minWidth="180px" label="操作人" prop="createBy">
            <template slot-scope="scope">
              <UserDialog
                @dialogChange="scope.row.createBy = $event.label"
                :echoValue="scope.row.createBy"
                :multiple="false"
                :openDisabled="openDisabled"
              />
<!--              <el-input v-model="scope.row.createBy" :disabled="openDisabled" />-->
            </template>
          </el-table-column>
          <!-- <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                placeholder="请输入备注"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column> -->
        </el-table>
      </el-form>

      <el-divider content-position="center"></el-divider>
      <el-row>
        <el-col :span="24">
          <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
          <div ref="main" style="width: 100%; height: 500px"></div>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWell,
  getWell,
  delWell,
  addWell,
  updateWell,
} from "@/api/quality/laboratory/well";

export default {
  name: "Well",
  data() {
    return {
      laboratory_well_sj: [],
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedQualityLabWellSub: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 水井水质分析简表格数据
      wellList: [],
      // 水井水质分析子表格数据
      qualityLabWellSubList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        sj: null,
        qynf: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
          qynf:  [{ required: true, message: "不能为空", trigger: "blur" }],
      },
      // 图表数据
      series: [],
    };
  },
  created() {
    this.getList();
    this.getDicts("laboratory_well_sj").then((response) => {
      this.laboratory_well_sj = response.data;
    });
  },
  methods: {
    /** 查询水井水质分析简列表 */
    getList() {
      this.loading = true;
      listWell(this.queryParams).then((response) => {
        this.wellList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 故障类型字典翻译
    laboratory_well_sj_Format(row, column) {
      return this.selectDictLabel(this.laboratory_well_sj, row.sj);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        month: null,
        sj: null,
        fu: null,
        lhw: null,
        xiu: null,
        xsy: null,
        lxy: null,
        na: null,
        jia: null,
        gai: null,
        mei: null,
        si: null,
        pgs: null,
        ad: null,
        meng: null,
        tie: null,
        yxsy: null,
        tsy: null,
        tsqy: null,
        ddl: null,
        tds: null,
        ph: null,
        xin: null,
        zk: null,
        qian: null,
        ge: null,
        ge2: null,
        nie: null,
        tong: null,
        qynf: null,
        bbbh: "LK-QF-LS1-10-015-11-02",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      };
      this.qualityLabWellSubList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.series = [];
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加水井水质分析简";
      this.handleAddQualityLabWellSub();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getWell(id).then((response) => {
        this.form = response.data;
        this.qualityLabWellSubList = response.data.qualityLabWellSubList;
        this.open = true;
        this.title = "修改水井水质分析简";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      getWell(id).then((response) => {
        this.form = response.data;
        this.qualityLabWellSubList = response.data.qualityLabWellSubList;
        this.open = true;
        this.title = "查看水井水质分析简";
        //查询数据
        this.initChart(response);
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.qualityLabWellSubList = this.qualityLabWellSubList;
          if (this.form.id != null) {
            updateWell(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            const rLoading = this.openLoading();
            addWell(this.form)
              .then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                rLoading.close();
                this.getList();
              })
              .catch((error) => {
                rLoading.close();
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除水井水质分析简编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delWell(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 水井水质分析子序号 */
    rowQualityLabWellSubIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 水井水质分析子添加按钮操作 */
    handleAddQualityLabWellSub() {
      const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
      arr.forEach((item) => {
        let obj = {};
        obj.month = item;
        obj.fu = "";
        obj.lhw = "";
        obj.xiu = "";
        obj.xsy = "";
        obj.lxy = "";
        obj.na = "";
        obj.jia = "";
        obj.gai = "";
        obj.mei = "";
        obj.si = "";
        obj.pgs = "";
        obj.ad = "";
        obj.meng = "";
        obj.tie = "";
        obj.yxsy = "";
        obj.tsy = "";
        obj.tsqy = "";
        obj.ddl = "";
        obj.tds = "";
        obj.ph = "";
        obj.xin = "";
        obj.zk = "";
        obj.qian = "";
        obj.ge = "";
        obj.ge2 = "";
        obj.nie = "";
        obj.tong = "";
        obj.qyrq = "";
        obj.remark = "";
        this.qualityLabWellSubList.push(obj);
      });
    },
    /** 水井水质分析子删除按钮操作 */
    handleDeleteQualityLabWellSub() {
      if (this.checkedQualityLabWellSub.length == 0) {
        this.$alert("请先选择要删除的水井水质分析子数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.qualityLabWellSubList.splice(
          this.checkedQualityLabWellSub[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleQualityLabWellSubSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.qualityLabWellSub.clearSelection();
        this.$refs.qualityLabWellSub.toggleRowSelection(selection.pop());
      } else {
        this.checkedQualityLabWellSub = selection;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "Laboratory_well/well/export",
        {
          ...this.queryParams,
        },
        "水井水质分析简" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    excelhandleView(row){
      this.download(
        "Laboratory/well/exportexcel?id="+row.id,
        {
          ...this.queryParams,
        },
        "水井水质分析简" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    //接收编号
    nameChange(e) {
      this.form.code = e;
    },
    /* 初始化echarts实例  */
    initChart(res) {
      this.$nextTick(() => {
        //基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(this.$refs.main);

        //中间对option数据进行处理
        let option = {
          backgroundColor: "#407EB4",
          title: {
            top: "3%",
            left: "45%",
            textStyle: {
              color: "#ffffff", //字体颜色
            },
          },
          // tooltip: {
          //   trigger: "axis",
          // },
          legend: {
            top: "4%",
            data: [
              "钙(mg/L)",
              "镁(mg/L)",
              "碳酸盐(mg/L)",
              "碳酸氢盐(mg/L)",
              "锶(mg/L)",
              "电导率(us/cm)",
              "TDS(mg/L)",
              "氯化物(mg/L)",
              "钠(mg/L)",
              "总砷(mg/L)",
              "硝酸盐(mg/L)",
              "硫酸盐(mg/L)",
              "氨氮(mg/L)",
              "钾(mg/L)",
              "铜(mg/L)",
              "溴(mg/L)",
              "铅(μg/L)",
              "锰(mg/L)",
              "铁(mg/L)",
              "亚硝酸盐(mg/L)",
              "PH值",
              "氟(mg/L)",
              "偏硅酸(mg/L)",
            ],
            type: "scroll", //设置legend滚动轴的出现
            textStyle: {
              color: "#ffffff", //字体颜色
            },
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "10%",
            containLabel: true,
          },
          toolbox: {
            feature: {
              saveAsImage: {},
            },
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: [
              "1",
              "2",
              "3",
              "4",
              "5",
              "6",
              "7",
              "8",
              "9",
              "10",
              "11",
              "12",
            ],
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
              },
            },
          },
          yAxis: {
            type: "value",
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
              },
            },
          },
          series: this.series,
        };
        /* 组装数据 */
        const arr1 = [
          "钙(mg/L)",
          "镁(mg/L)",
          "碳酸盐(mg/L)",
          "碳酸氢盐(mg/L)",
          "锶(mg/L)",
          "电导率(us/cm)",
          "TDS(mg/L)",
          "氯化物(mg/L)",
          "钠(mg/L)",
          "总砷(mg/L)",
          "硝酸盐(mg/L)",
          "硫酸盐(mg/L)",
          "氨氮(mg/L)",
          "钾(mg/L)",
          "铜(mg/L)",
          "溴(mg/L)",
          "铅(μg/L)",
          "锰(mg/L)",
          "铁(mg/L)",
          "亚硝酸盐(mg/L)",
          "PH值",
          "氟(mg/L)",
          "偏硅酸(mg/L)",
        ];
        const arr2 = [
          "gai",
          "mei",
          "tsy",
          "tsqy",
          "si",
          "ddl",
          "tds",
          "lhw",
          "na",
          "zk",
          "xsy",
          "lxy",
          "ad",
          "jia",
          "tong",
          "xiu",
          "qian",
          "meng",
          "tie",
          "yxsy",
          "ph",
          "fu",
          "pgs",
        ];
        let con = 0;
        arr1.forEach((a) => {
          const obj = {};
          obj.name = a;
          obj.type = "line";
          const nclist = [];
          res.data.qualityLabWellSubList.forEach((item) => {
            nclist.push(item[arr2[con]]);
          });
          con++;
          obj.data = nclist;
          this.series.push(obj);
        });

        myChart.setOption(option);
      });
    },
  },
};
</script>
